package com.wangsh.userscenter.client.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wangsh.userscenter.common.controller.BaseController;
import com.wangsh.userscenter.service.users.api.IUsersService;

/**
 * 用户登陆后的主页面
 * @author wangsh_sxt
 *
 */
@Controller
@RequestMapping("/head/users/")
public class UsersHeadController extends BaseController
{
	@Autowired
	private IUsersService usersService;
	
	/**
	 * 用户首页
	 * @return
	 */
	@RequestMapping("/main.html")
	public String main()
	{
		return "/head/users/main";
	}
	
	/**
	 * 退出操作
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/logout.html")
	public String logout(HttpServletRequest request,HttpServletResponse response) throws Exception
	{
		info = "成功退出" ; 
		HttpSession session = request.getSession();
		session.removeAttribute("users");
		
		String returnUrl = request.getParameter("returnUrl");
		if(returnUrl == null)
		{
			returnUrl = "" ; 
		}
		returnUrl = URLEncoder.encode(returnUrl, "UTF-8");
		ResourceBundle bundle = ResourceBundle.getBundle("client");
		String logoutUrl = bundle.getString("sso.users.logout");
		logoutUrl += "?returnUrl=" + returnUrl;
		response.sendRedirect(logoutUrl);
		return null;
	}
}
